package com.jiai.cloud.community.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jiai.cloud.base.page.CustomPage;
import com.jiai.cloud.community.entity.ToPicSearch;
import com.jiai.cloud.community.mapper.TCommentMapper;
import com.jiai.cloud.community.mapper.TTemplateMapper;
import com.jiai.cloud.community.mapper.TTopicMapper;
import com.jiai.cloud.community.service.ITTopicService;
import com.jiai.cloud.community.entity.TTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-06-07
 */
@Service
public class TTopicServiceImpl extends ServiceImpl<TTopicMapper, TTopic> implements ITTopicService {


    @Autowired
    private TTemplateMapper templateMapper;
    @Autowired
    private TTopicMapper tTopicMapper;


    @Override
    public Map<String, Object> countTopicIndexData() {
        Map<String,Object> dataMap=new HashMap();
        //查询当天时间的总数
        int nowTopicTotal= baseMapper.selectCount(new EntityWrapper().and("DATE_FORMAT(time,'%Y%M%D')=DATE_FORMAT(now(),'%Y%M%D')"));
        //查询话题的总记录数
        int topicTotal=baseMapper.selectCount(null);
        dataMap.put("topicTotal",topicTotal);
        //查询当前话题的分类
        dataMap.put("templates",templateMapper.selectTemaplByAllForJOINClassify());
        dataMap.put("nowTopicTotal",nowTopicTotal);
        return dataMap;
    }

    @Override
    public CustomPage selecttopicByAllForJOINUser(ToPicSearch search) {
        EntityWrapper wrapper=new EntityWrapper();
        Page page=search.getPagePlus();
        if(search.getClassifyId()!=null){
            wrapper.eq("classifyId",search.getClassifyId());
        }
        if(search.getTemplateId()!=null){
            wrapper.eq("templateId",search.getTemplateId());
        }
        if(search.getTopicType()!=null)
        switch (search.getTopicType()){
            case 1:
                wrapper.eq("stick",1);
                break;
            case 2:
                wrapper.eq("boutique",1);
                break;
            case 3:
                wrapper.isNotNull("banner").and("t.banner<>''");
                break;
        }

        page.setRecords(baseMapper.selecttopicByAllForJOINUser(page,wrapper));
        return new CustomPage(page);
    }


}
